EDA danych dotyczących Titanica¶

O Danych¶

Dane o pasażerach Titanica

Zbiór danych zawiera informacje o pasażerach RMS Titanic, który zatonął 15 kwietnia 1912 roku po zderzeniu z górą lodową. Dane obejmują takie atrybuty jak klasa podróży, wiek, płeć, liczba rodzeństwa/małżonków na pokładzie, liczba rodziców/dzieci na pokładzie, cena biletu oraz miejsce zaokrętowania.

Zbiór zawiera także informację o tym, czy pasażer przeżył katastrofę.

Titanic przewoził ponad 2,200 osób, z czego ponad 1,500 zginęło, co czyni tę katastrofę jedną z najbardziej tragicznych w historii morskiej.

Kolumny:

  • pclass - Klasa biletu
  • survived - Czy pasażer przeżył katastrofę
  • name - Imię i nazwisko pasażera
  • sex - Płeć pasażera
  • age - Wiek pasażera
  • sibsp - Liczba rodzeństwa/małżonków na pokładzie
  • parch - Liczba rodziców/dzieci na pokładzie
  • ticket - Numer biletu
  • fare - Cena biletu
  • cabin - Numer kabiny
  • embarked - Port, w którym pasażer wszedł na pokład (C = Cherbourg, Q = Queenstown, S = Southampton)
  • boat - Numer łodzi ratunkowej
  • body - Numer ciała (jeśli pasażer nie przeżył i ciało zostało odnalezione)
  • home.dest - Miejsce docelowe
In [1]:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
In [2]:
df = pd.read_csv('26__titanic.csv', sep=",")
df
Out[2]:
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body home.dest
0 1.0 1.0 Allen, Miss. Elisabeth Walton female 29.0000 0.0 0.0 24160 211.3375 B5 S 2 NaN St Louis, MO
1 1.0 1.0 Allison, Master. Hudson Trevor male 0.9167 1.0 2.0 113781 151.5500 C22 C26 S 11 NaN Montreal, PQ / Chesterville, ON
2 1.0 0.0 Allison, Miss. Helen Loraine female 2.0000 1.0 2.0 113781 151.5500 C22 C26 S NaN NaN Montreal, PQ / Chesterville, ON
3 1.0 0.0 Allison, Mr. Hudson Joshua Creighton male 30.0000 1.0 2.0 113781 151.5500 C22 C26 S NaN 135.0 Montreal, PQ / Chesterville, ON
4 1.0 0.0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels) female 25.0000 1.0 2.0 113781 151.5500 C22 C26 S NaN NaN Montreal, PQ / Chesterville, ON
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1305 3.0 0.0 Zabour, Miss. Thamine female NaN 1.0 0.0 2665 14.4542 NaN C NaN NaN NaN
1306 3.0 0.0 Zakarian, Mr. Mapriededer male 26.5000 0.0 0.0 2656 7.2250 NaN C NaN 304.0 NaN
1307 3.0 0.0 Zakarian, Mr. Ortin male 27.0000 0.0 0.0 2670 7.2250 NaN C NaN NaN NaN
1308 3.0 0.0 Zimmerman, Mr. Leo male 29.0000 0.0 0.0 315082 7.8750 NaN S NaN NaN NaN
1309 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

1310 rows × 14 columns

In [4]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1310 entries, 0 to 1309
Data columns (total 14 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   pclass     1309 non-null   float64
 1   survived   1309 non-null   float64
 2   name       1309 non-null   object 
 3   sex        1309 non-null   object 
 4   age        1046 non-null   float64
 5   sibsp      1309 non-null   float64
 6   parch      1309 non-null   float64
 7   ticket     1309 non-null   object 
 8   fare       1308 non-null   float64
 9   cabin      295 non-null    object 
 10  embarked   1307 non-null   object 
 11  boat       486 non-null    object 
 12  body       121 non-null    float64
 13  home.dest  745 non-null    object 
dtypes: float64(7), object(7)
memory usage: 143.4+ KB
In [5]:
df.sample(10)
Out[5]:
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body home.dest
1121 3.0 1.0 Peter, Master. Michael J male NaN 1.0 1.0 2668 22.3583 NaN C C NaN NaN
264 1.0 1.0 Simonius-Blumer, Col. Oberst Alfons male 56.0 0.0 0.0 13213 35.5000 A26 C 3 NaN Basel, Switzerland
1029 3.0 0.0 Moran, Mr. Daniel J male NaN 1.0 0.0 371110 24.1500 NaN Q NaN NaN NaN
410 2.0 0.0 Frost, Mr. Anthony Wood "Archie" male NaN 0.0 0.0 239854 0.0000 NaN S NaN NaN Belfast
1226 3.0 0.0 Stoytcheff, Mr. Ilia male 19.0 0.0 0.0 349205 7.8958 NaN S NaN NaN NaN
139 1.0 1.0 Graham, Mrs. William Thompson (Edith Junkins) female 58.0 0.0 1.0 PC 17582 153.4625 C125 S 3 NaN Greenwich, CT
218 1.0 1.0 Oliva y Ocana, Dona. Fermina female 39.0 0.0 0.0 PC 17758 108.9000 C105 C 8 NaN NaN
418 2.0 0.0 Gilbert, Mr. William male 47.0 0.0 0.0 C.A. 30769 10.5000 NaN S NaN NaN Cornwall
1291 3.0 0.0 Willer, Mr. Aaron ("Abi Weller") male NaN 0.0 0.0 3410 8.7125 NaN S NaN NaN NaN
1189 3.0 1.0 Sandstrom, Miss. Marguerite Rut female 4.0 1.0 1.0 PP 9549 16.7000 G6 S 13 NaN NaN
In [6]:
df.nunique()
Out[6]:
pclass          3
survived        2
name         1307
sex             2
age            98
sibsp           7
parch           8
ticket        929
fare          281
cabin         186
embarked        3
boat           27
body          121
home.dest     369
dtype: int64
In [7]:
df.isnull().sum()
Out[7]:
pclass          1
survived        1
name            1
sex             1
age           264
sibsp           1
parch           1
ticket          1
fare            2
cabin        1015
embarked        3
boat          824
body         1189
home.dest     565
dtype: int64
In [10]:
duplicates = df[df.duplicated()]
duplicates
Out[10]:
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body home.dest
In [16]:
df['home.dest'].unique()
Out[16]:
array(['St Louis, MO', 'Montreal, PQ / Chesterville, ON', 'New York, NY',
       'Hudson, NY', 'Belfast, NI', 'Bayside, Queens, NY',
       'Montevideo, Uruguay', 'Paris, France', nan, 'Hessle, Yorks',
       'Montreal, PQ', 'Winnipeg, MN', 'San Francisco, CA',
       'Dowagiac, MI', 'Stockholm, Sweden / Washington, DC',
       'Trenton, NJ', 'Glen Ridge, NJ', 'Youngstown, OH',
       'Birkdale, England Cleveland, Ohio', 'London / Winnipeg, MB',
       'Cooperstown, NY', 'St Leonards-on-Sea, England Ohio',
       'Los Angeles, CA', 'Pomeroy, WA', 'Omaha, NE', 'Philadelphia, PA',
       'Denver, CO', 'Belmont, MA', 'Washington, DC',
       'Austria-Hungary / Germantown, Philadelphia, PA',
       'Germantown, Philadelphia, PA', 'Bryn Mawr, PA',
       'Ascot, Berkshire / Rochester, NY', 'Little Onn Hall, Staffs',
       'Amenia, ND', 'New York, NY / Ithaca, NY', 'London, England',
       'Liverpool, England / Belfast', 'Stoughton, MA', 'Victoria, BC',
       'Lakewood, NJ', 'Roachdale, IN', 'Milwaukee, WI', 'Lima, Peru',
       'Calgary, AB', 'Deephaven, MN / Cedar Rapids, IA',
       'London / Paris', 'Mt Airy, Philadelphia, PA', 'Brookline, MA',
       'Brooklyn, NY', 'Winnipeg, MB', 'Westcliff-on-Sea, Essex',
       'Zurich, Switzerland', 'Scituate, MA',
       "St Anne's-on-Sea, Lancashire", 'Paris, France / New York, NY',
       'Greenwich, CT', 'Kingston, Surrey', 'London / Middlesex',
       'Brighton, MA', 'London / Birmingham', 'Chicago, IL',
       'Indianapolis, IN', 'New York, NY /  Stamford CT',
       'Paris, France New York, NY', 'Liverpool', 'Bennington, VT',
       'London', 'Buffalo, NY', 'Southington / Noank, CT', 'Boston, MA',
       'Portland, OR', 'Stockholm, Sweden', 'Springfield, MA',
       'London / New York, NY', 'Brockton, MA', 'Belgium  Montreal, PQ',
       'Vancouver, BC', 'Dorchester, MA', 'East Bridgewater, MA',
       'Fond du Lac, WI', 'Green Bay, WI', 'Lexington, MA',
       'Isle of Wight, England', 'Providence, RI', '?Havana, Cuba',
       'Belfast', 'Surbiton Hill, Surrey', 'Isleworth, England',
       'Madrid, Spain', 'Toronto, ON', 'Worcester, MA',
       'Rotterdam, Netherlands', 'Paris /  New York, NY', 'Seattle, WA',
       'London  Vancouver, BC', 'Haverford, PA / Cooperstown, NY',
       'Manchester, England', 'New York, NY / Greenwich CT', 'Duluth, MN',
       'Basel, Switzerland', 'New Britain, CT',
       'St James, Long Island, NY', 'Huntington, WV', 'Streatham, Surrey',
       'Minneapolis, MN', 'Tuxedo Park, NY',
       'Wimbledon Park, London / Hayling Island, Hants', 'Newark, NJ',
       'Haverford, PA', 'Gallipolis, Ohio / ? Paris / New York',
       'Cincinatti, OH', 'Haddenfield, NJ', 'London /  East Orange, NJ',
       'Albany, NY', 'Mexico City, Mexico', 'East Orange, NJ',
       'England Salt Lake City, Utah', 'Brunswick, ME',
       'New York, NY / Briarcliff Manor NY', 'Elkins Park, PA',
       'Geneva, Switzerland / Radnor, PA', 'Halifax, NS',
       'New York, NY / Washington, DC', 'Russia New York, NY',
       'Bryn Mawr, PA, USA', 'Buenos Aires, Argentina / New Jersey, NJ',
       'Cornwall, England Houghton, MI', 'Warwick, England',
       'West Hoboken, NJ', 'Penzance, Cornwall / Akron, OH', 'Guernsey',
       'Bristol, Avon / Jacksonville, FL',
       'Plymouth, Dorset / Houghton, MI', 'Jacksonville, FL',
       'Norwich / New York, NY', 'England',
       'Guntur, India / Benton Harbour, MI', 'Rochester, NY',
       'St Ives, Cornwall / Calumet, MI', 'Elmira, NY / Orange, NJ',
       'Lake Arthur, Chavez County, NM', 'London / Montreal, PQ',
       'Cape Town, South Africa / Seattle, WA',
       'Skara, Sweden / Rockford, IL',
       'Sittingbourne, England / San Diego, CA', 'Southsea, Hants',
       'Bangkok, Thailand / Roseville, IL', 'Mamaroneck, NY', 'Bronx, NY',
       'Cornwall / Spokane, WA', 'England / San Francisco, CA',
       'Hartford, Huntingdonshire', 'Helsinki, Finland Ashtabula, Ohio',
       'London / Fort Byron, NY',
       'Bishopstoke, Hants / Fayette Valley, ID', 'Pennsylvania',
       'Provo, UT', 'Upper Burma, India Pittsburgh, PA',
       'St Ives, Cornwall / Hancock, MI', 'Lyndhurst, England',
       'London / Staten Island, NY', 'Portugal / Sau Paulo, Brazil',
       'Lucca, Italy / California', 'Guernsey / Elizabeth, NJ',
       'New Forest, England', 'Southampton', 'Holley, NY',
       'Greenport, NY', 'Barcelona, Spain / Havana, Cuba',
       'England / Detroit, MI', 'Goteborg, Sweden / Rockford, IL',
       'Oslo, Norway Bayonne, NJ', 'England / Philadelphia, PA',
       'Cornwall / Houghton, MI', 'Janjgir, India / Pennsylvania',
       'Liverpool / Montreal, PQ', 'Cornwall / Clear Creek, CO',
       'Cornwall', 'Cornwall / Camden, NJ', 'West Kensington, London',
       'Clevedon, England', 'Auburn, NY', 'Detroit, MI',
       'Seattle, WA / Toledo, OH', 'Denmark Hill, Surrey / Chicago',
       'Walthamstow, England', 'Ilford, Essex / Winnipeg, MB',
       'Somerset / Bernardsville, NJ', 'India / Rapid City, SD',
       'West Hampstead, London / Neepawa, MB',
       'Kontiolahti, Finland / Detroit, MI', 'Cornwall / Akron, OH',
       'Devonport, England', 'England / Sacramento, CA', 'Tokyo, Japan',
       'Swindon, England', 'North Evington, England',
       'St Ives, Cornwall / Houghton, MI', 'Moscow / Bronx, NY',
       'India / Pittsburgh, PA', 'Harrisburg, PA', 'Glasgow / Bangor, ME',
       'Sweden / Arlington, NJ', 'Paris / Haiti',
       'Berne, Switzerland / Central City, IA', 'London / Chicago, IL',
       'Weston-Super-Mare, Somerset', 'Southampton / New York, NY',
       'Paris', 'Paris / Montreal, PQ', 'St Austall, Cornwall',
       'Weston-Super-Mare / Moose Jaw, SK', 'Sydney, Australia',
       'Sarnia, ON', 'England / Bennington, VT', 'Chelsea, London',
       'Harrow-on-the-Hill, Middlesex', 'Copenhagen, Denmark',
       'Guernsey / Montclair, NJ and/or Toledo, Ohio', 'Frankfort, KY',
       'Halesworth, England', 'Cambridge, MA', 'Nice, France',
       'Cornwall / Hancock, MI', 'Glasgow', 'Cologne, Germany',
       'Folkstone, Kent / New York, NY', 'Middleburg Heights, OH',
       'Pondersend, England / New Durham, NJ', 'Spain / Havana, Cuba',
       'Hamilton, ON', 'St Andrews, Guernsey', 'Woodford County, KY',
       'Gunnislake, England / Butte, MT', 'Ilfracombe, Devon',
       'Worcester, England', 'Russia', 'Denmark / New York, NY',
       'Milford, NH', 'Plymouth, Devon / Detroit, MI', 'Brighton, Sussex',
       'Elizabeth, NJ', 'Spain',
       'London, England / Marietta, Ohio and Milwaukee, WI',
       'Guernsey / Wilmington, DE', 'Hornsey, England', 'Deer Lodge, MT',
       'Finland / Minneapolis, MN', 'Finland / Washington, DC',
       'Sault St Marie, ON', 'Catford, Kent / Detroit, MI',
       'Columbus, OH', 'Bath, England / Massachusetts',
       'Plymouth, England', 'Barre, Co Washington, VT',
       'Bristol, England / New Britain, CT', 'Aberdeen / Portland, OR',
       'England / Hartford, CT', 'Bromsgrove, England / Montreal, PQ',
       'Bournmouth, England', 'Guernsey, England / Edgewood, RI',
       'Harrow, England', 'Yoevil, England / Cottage Grove, OR',
       'East Providence, RI', 'Norway Los Angeles, CA',
       'Perkins County, SD', 'Taalintehdas, Finland Hoboken, NJ',
       'Greensburg, PA', 'Asarum, Sweden Brooklyn, NY',
       'Bournemouth, England', 'Sweden Akeley, MN',
       'London, England Norfolk, VA', 'Syria Fredericksburg, VA',
       'England Albion, NY', 'Salo, Finland Astoria, OR', 'Argentina',
       'Lower Clapton, Middlesex or Erdington, Birmingham',
       'Windsor, England New York, NY', 'Bergen, Norway',
       'Sweden Winnipeg, MN', 'Ruotsinphyhtaa, Finland New York, NY',
       'Vadsbro, Sweden Ministee, MI', 'Hartford, CT',
       'Sweden Chicago, IL', 'Bulgaria Chicago, IL',
       'Altdorf, Switzerland', 'Sweden Joliet, IL',
       'Sweden  Worcester, MA', 'Sweden Worcester, MA',
       'Oskarshamn, Sweden Minneapolis, MN', 'Ottawa, ON',
       'Krakoryd, Sweden Bloomington, IL', 'Syria Youngstown, OH',
       'Ruotsinphytaa, Finland New York, NY', 'Syria New York, NY',
       'London Skanteales, NY', 'Syria Ottawa, ON',
       'England New York, NY', 'Krakudden, Sweden Moune, IL',
       'Tranvik, Finland New York', 'Syria', 'Hong Kong New York, NY',
       'Brennes, Norway New York', 'Stockholm, Sweden New York',
       'Syria Kent, ON', 'Ireland Chicago, IL',
       'Treherbert, Cardiff, Wales',
       'Kingwilliamstown, Co Cork, Ireland Glens Falls, NY',
       'Medeltorp, Sweden Chicago, IL', 'Bridgerule, Devon',
       'Broomfield, Chelmsford, England', 'Co Cork, Ireland Roxbury, MA',
       'Kingwilliamstown, Co Cork, Ireland New York, NY',
       'Co Cork, Ireland Charlestown, MA',
       'Co Sligo, Ireland New York, NY', 'Croatia',
       'Ireland Philadelphia, PA', 'Dagsas, Sweden Fower, MN',
       'Goteborg, Sweden Huntley, IL',
       'Co Longford, Ireland New York, NY',
       'Co Sligo, Ireland Hartford, CT', 'St Denys, Southampton, Hants',
       'Ireland New York, NY', 'Greece', 'Portugal',
       'London Brooklyn, NY', 'Co Limerick, Ireland Sherbrooke, PQ',
       'Ireland Brooklyn, NY', 'Ireland', 'Austria',
       'England Brooklyn, NY', 'Merrill, WI',
       'Bristol, England Cleveland, OH',
       'Bournemouth, England Newark, NJ', 'Austria-Hungary',
       'Australia Fingal, ND', 'Norrlot, Sweden Chicago, IL',
       'Co Athlone, Ireland New York, NY', 'Stanton, IA',
       'West Bromwich, England Pontiac, MI',
       'Liverpool, England Bedford, OH', 'Tampico, MT',
       'Belgium Detroit, MI', 'Devon, England Wichita, KS',
       'Bulgaria Coon Rapids, IA',
       'Kilmacowen, Co Sligo, Ireland New York, NY',
       'England Oglesby, IL', 'Union Hill, NJ', 'London New York, NY',
       'Austria Niagara Falls, NY', 'West Haven, CT',
       'Tofta, Sweden Joliet, IL', 'Karberg, Sweden Jerome Junction, AZ',
       'Effington Rut, SD', 'Illinois, USA',
       'Aughnacliff, Co Longford, Ireland New York, NY',
       'Italy Philadelphia, PA',
       'Rotherfield, Sussex, England Essex Co, MA',
       'Bridgwater, Somerset, England',
       'Co Clare, Ireland Washington, DC',
       'Strood, Kent, England Detroit, MI',
       'Wiltshire, England Niagara Falls, NY', 'Dorking, Surrey, England',
       'Foresvik, Norway Portland, ND', 'Waukegan, Chicago, IL',
       'Myren, Sweden New York, NY', 'Finland Sudbury, ON',
       'Oslo, Norway Cameron, WI', 'Antwerp, Belgium / Stanton, OH'],
      dtype=object)
In [19]:
df.isnull().sum()
Out[19]:
pclass          1
survived        1
name            1
sex             1
age           264
sibsp           1
parch           1
ticket          1
fare            2
cabin        1015
embarked        3
boat          824
body         1189
home.dest     565
dtype: int64

Najczęściej brakuje informacji o numerze kabiny, numerze ciała i łodzi ratunkowej.¶

In [20]:
df["sex"].value_counts()
Out[20]:
male      843
female    466
Name: sex, dtype: int64

Na statku było dwa razy więcej mężczyzn.¶

In [7]:
df['sex'].replace(['female', 'male'], [0, 1], inplace=True)
In [24]:
df.sample(10)
Out[24]:
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body home.dest
990 3.0 0.0 Makinen, Mr. Kalle Edvard 1.0 29.0 0.0 0.0 STON/O 2. 3101268 7.9250 NaN S NaN NaN NaN
362 2.0 1.0 Cameron, Miss. Clear Annie 0.0 35.0 0.0 0.0 F.C.C. 13528 21.0000 NaN S 14 NaN Mamaroneck, NY
1239 3.0 0.0 Theobald, Mr. Thomas Leonard 1.0 34.0 0.0 0.0 363294 8.0500 NaN S NaN 176.0 NaN
966 3.0 0.0 Lindahl, Miss. Agda Thorilda Viktoria 0.0 25.0 0.0 0.0 347071 7.7750 NaN S NaN NaN NaN
74 1.0 0.0 Clifford, Mr. George Quincy 1.0 NaN 0.0 0.0 110465 52.0000 A14 S NaN NaN Stoughton, MA
142 1.0 0.0 Guggenheim, Mr. Benjamin 1.0 46.0 0.0 0.0 PC 17593 79.2000 B82 B84 C NaN NaN New York, NY
460 2.0 1.0 Jacobsohn, Mrs. Sidney Samuel (Amy Frances Chr... 0.0 24.0 2.0 1.0 243847 27.0000 NaN S 12 NaN London
377 2.0 1.0 Collyer, Miss. Marjorie "Lottie" 0.0 8.0 0.0 2.0 C.A. 31921 26.2500 NaN S 14 NaN Bishopstoke, Hants / Fayette Valley, ID
855 3.0 0.0 Hassan, Mr. Houssein G N 1.0 11.0 0.0 0.0 2699 18.7875 NaN C NaN NaN NaN
511 2.0 0.0 Myles, Mr. Thomas Francis 1.0 62.0 0.0 0.0 240276 9.6875 NaN Q NaN NaN Cambridge, MA
In [25]:
df.mean(numeric_only=True)
Out[25]:
pclass        2.294882
survived      0.381971
sex           0.644003
age          29.881135
sibsp         0.498854
parch         0.385027
fare         33.295479
body        160.809917
dtype: float64
In [5]:
df.groupby("survived").describe().transpose()
Out[5]:
survived 0.0 1.0
pclass count 809.000000 500.000000
mean 2.500618 1.962000
std 0.744825 0.872972
min 1.000000 1.000000
25% 2.000000 1.000000
50% 3.000000 2.000000
75% 3.000000 3.000000
max 3.000000 3.000000
age count 619.000000 427.000000
mean 30.545369 28.918228
std 13.922539 15.061481
min 0.333300 0.166700
25% 21.000000 20.000000
50% 28.000000 28.000000
75% 39.000000 38.000000
max 74.000000 80.000000
sibsp count 809.000000 500.000000
mean 0.521632 0.462000
std 1.210449 0.685197
min 0.000000 0.000000
25% 0.000000 0.000000
50% 0.000000 0.000000
75% 1.000000 1.000000
max 8.000000 4.000000
parch count 809.000000 500.000000
mean 0.328801 0.476000
std 0.912332 0.776292
min 0.000000 0.000000
25% 0.000000 0.000000
50% 0.000000 0.000000
75% 0.000000 1.000000
max 9.000000 5.000000
fare count 808.000000 500.000000
mean 23.353831 49.361184
std 34.145096 68.648795
min 0.000000 0.000000
25% 7.854200 11.214600
50% 10.500000 26.000000
75% 26.000000 57.750000
max 263.000000 512.329200
body count 121.000000 0.000000
mean 160.809917 NaN
std 97.696922 NaN
min 1.000000 NaN
25% 72.000000 NaN
50% 155.000000 NaN
75% 256.000000 NaN
max 328.000000 NaN

Mediana dla wieku to 29.8. Najmłodszy pasażer nie miał roku, a najstarszy miał 80 lat. Czy oni przeżyli?¶

In [6]:
df[(df['age'] == 80) & (df['survived'] == 1)].count()
Out[6]:
pclass       1
survived     1
name         1
sex          1
age          1
sibsp        1
parch        1
ticket       1
fare         1
cabin        1
embarked     1
boat         1
body         0
home.dest    1
dtype: int64

Najstarszy pasażer przeżył.¶

In [3]:
df[(df['age'] < 1)].count()
Out[3]:
pclass       12
survived     12
name         12
sex          12
age          12
sibsp        12
parch        12
ticket       12
fare         12
cabin         1
embarked     12
boat         10
body          0
home.dest    10
dtype: int64

Płynęło 12 niemowlaków.¶

In [96]:
df[(df['age'] < 1) & (df['survived'] == 1)].count()
Out[96]:
pclass       10
survived     10
name         10
sex          10
age          10
sibsp        10
parch        10
ticket       10
fare         10
cabin         1
embarked     10
boat         10
body          0
home.dest     9
dtype: int64
In [98]:
df[(df['age'] < 1) & (df['survived'] == 0)].count()
Out[98]:
pclass       2
survived     2
name         2
sex          2
age          2
sibsp        2
parch        2
ticket       2
fare         2
cabin        0
embarked     2
boat         0
body         0
home.dest    1
dtype: int64

2 niemowlaków zginęło.¶

In [13]:
df[(df['age'] < 1) & (df['survived'] == 0)].mode()
Out[13]:
pclass survived name sex age sibsp parch ticket fare cabin embarked boat body home.dest
0 3.0 0.0 Danbom, Master. Gilbert Sigvard Emanuel male 0.3333 0.0 1.0 347080 13.775 NaN S NaN NaN Stanton, IA
1 NaN NaN Peacock, Master. Alfred Edward NaN 0.7500 1.0 2.0 SOTON/O.Q. 3101315 14.400 NaN NaN NaN NaN NaN

Niemowlaki nie były spokrewnione.¶

In [21]:
df["ticket"].value_counts()
Out[21]:
CA. 2343    11
1601         8
CA 2144      8
PC 17608     7
347077       7
            ..
373450       1
2223         1
350046       1
3101281      1
315082       1
Name: ticket, Length: 929, dtype: int64
In [34]:
df["home.dest"].value_counts()
Out[34]:
New York, NY                                    64
London                                          14
Montreal, PQ                                    10
Paris, France                                    9
Cornwall / Akron, OH                             9
                                                ..
Chelsea, London                                  1
Harrow-on-the-Hill, Middlesex                    1
Copenhagen, Denmark                              1
Guernsey / Montclair, NJ and/or Toledo, Ohio     1
Antwerp, Belgium / Stanton, OH                   1
Name: home.dest, Length: 369, dtype: int64

Najczęściej płynęłi do Nowego Jorku.¶

In [22]:
df["name"].value_counts()
Out[22]:
Connolly, Miss. Kate             2
Kelly, Mr. James                 2
Allen, Miss. Elisabeth Walton    1
Ilmakangas, Miss. Ida Livija     1
Ilieff, Mr. Ylio                 1
                                ..
Hart, Miss. Eva Miriam           1
Harris, Mr. Walter               1
Harris, Mr. George               1
Harper, Rev. John                1
Zimmerman, Mr. Leo               1
Name: name, Length: 1307, dtype: int64
In [27]:
df["name"].value_counts().duplicated()
Out[27]:
Connolly, Miss. Kate             False
Kelly, Mr. James                  True
Allen, Miss. Elisabeth Walton    False
Ilmakangas, Miss. Ida Livija      True
Ilieff, Mr. Ylio                  True
                                 ...  
Hart, Miss. Eva Miriam            True
Harris, Mr. Walter                True
Harris, Mr. George                True
Harper, Rev. John                 True
Zimmerman, Mr. Leo                True
Name: name, Length: 1307, dtype: bool
In [26]:
df.duplicated(subset='name', keep=False)
Out[26]:
0       False
1       False
2       False
3       False
4       False
        ...  
1305    False
1306    False
1307    False
1308    False
1309    False
Length: 1310, dtype: bool

Mamy dwie pary osób o takim samym imieniu i nazwisku, bo wiersze nie są zdublowane.¶

In [30]:
df["survived"].value_counts()
Out[30]:
0.0    809
1.0    500
Name: survived, dtype: int64

Przeżyło 500 osób.¶

In [31]:
df["pclass"].value_counts()
Out[31]:
3.0    709
1.0    323
2.0    277
Name: pclass, dtype: int64

Najwięcej osób płynęło w klasie 3.¶

In [33]:
df.groupby("pclass", as_index=False)["survived"].value_counts()
Out[33]:
pclass survived count
0 1.0 1.0 200
1 1.0 0.0 123
2 2.0 0.0 158
3 2.0 1.0 119
4 3.0 0.0 528
5 3.0 1.0 181

Zestawienie osób, które przeżyły, a które nie przeżyły w każdej klasie. Najwięcej osób, które utonęły, płynęło w klasie 3.¶

In [17]:
df.groupby("survived", as_index=False)["age"].value_counts()
Out[17]:
survived age count
0 0.0 21.0000 30
1 0.0 30.0000 25
2 0.0 24.0000 25
3 0.0 18.0000 25
4 0.0 28.0000 24
... ... ... ...
154 1.0 0.1667 1
155 1.0 0.4167 1
156 1.0 0.6667 1
157 1.0 11.0000 1
158 1.0 80.0000 1

159 rows × 3 columns

Najwięcej pasażerów-ofiar miało 21 lat.¶

In [24]:
df.groupby("survived", as_index=False)["age"].value_counts()
Out[24]:
survived age count
0 0.0 21.0000 30
1 0.0 30.0000 25
2 0.0 24.0000 25
3 0.0 18.0000 25
4 0.0 28.0000 24
... ... ... ...
154 1.0 0.1667 1
155 1.0 0.4167 1
156 1.0 0.6667 1
157 1.0 11.0000 1
158 1.0 80.0000 1

159 rows × 3 columns

In [108]:
df["age"].value_counts()
Out[108]:
24.0000    47
22.0000    43
21.0000    41
30.0000    40
18.0000    39
           ..
0.3333      1
22.5000     1
70.5000     1
0.6667      1
26.5000     1
Name: age, Length: 98, dtype: int64

Najwięcej osób miało 24 lata¶

In [110]:
df['embarked'].value_counts()
Out[110]:
S    914
C    270
Q    123
Name: embarked, dtype: int64

Najczęściej wchodzili portem Southampton, najrzadziej Queenstown.¶

In [22]:
df.groupby("embarked", as_index=False)["survived"].value_counts()
Out[22]:
embarked survived count
0 C 1.0 150
1 C 0.0 120
2 Q 0.0 79
3 Q 1.0 44
4 S 0.0 610
5 S 1.0 304
In [23]:
df.groupby("sibsp", as_index=False)["survived"].value_counts()
Out[23]:
sibsp survived count
0 0.0 0.0 582
1 0.0 1.0 309
2 1.0 1.0 163
3 1.0 0.0 156
4 2.0 0.0 23
5 2.0 1.0 19
6 3.0 0.0 14
7 3.0 1.0 6
8 4.0 0.0 19
9 4.0 1.0 3
10 5.0 0.0 6
11 8.0 0.0 9
In [24]:
df.groupby("parch", as_index=False)["survived"].value_counts()
Out[24]:
parch survived count
0 0.0 0.0 666
1 0.0 1.0 336
2 1.0 1.0 100
3 1.0 0.0 70
4 2.0 1.0 57
5 2.0 0.0 56
6 3.0 1.0 5
7 3.0 0.0 3
8 4.0 0.0 5
9 4.0 1.0 1
10 5.0 0.0 5
11 5.0 1.0 1
12 6.0 0.0 2
13 9.0 0.0 2
In [56]:
df["parch"].value_counts()
Out[56]:
0.0    1002
1.0     170
2.0     113
3.0       8
4.0       6
5.0       6
6.0       2
9.0       2
Name: parch, dtype: int64

Najwięcej osób podróżowało samotnie, z jedną osobą podróżowało 170 osób, a z dwiema 113 osób.¶

In [4]:
df.corr(numeric_only=True)
Out[4]:
pclass survived sex age sibsp parch fare body
pclass 1.000000 -0.312469 0.124617 -0.408106 0.060832 0.018322 -0.558629 -0.034642
survived -0.312469 1.000000 -0.528693 -0.055513 -0.027825 0.082660 0.244265 NaN
sex 0.124617 -0.528693 1.000000 0.063646 -0.109609 -0.213125 -0.185523 -0.015903
age -0.408106 -0.055513 0.063646 1.000000 -0.243699 -0.150917 0.178739 0.058809
sibsp 0.060832 -0.027825 -0.109609 -0.243699 1.000000 0.373587 0.160238 -0.099961
parch 0.018322 0.082660 -0.213125 -0.150917 0.373587 1.000000 0.221539 0.051099
fare -0.558629 0.244265 -0.185523 0.178739 0.160238 0.221539 1.000000 -0.043110
body -0.034642 NaN -0.015903 0.058809 -0.099961 0.051099 -0.043110 1.000000
In [26]:
matryca_kor = df.corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(matryca_kor, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji")
plt.show()
No description has been provided for this image

Płeć nie koreluje z przeżywalnością, ale widać małą korelację z klasą. Wiek - mała korelacja z ceną biletu. Największa korelacja między liczbą małżonków/rodzeństwa a rodziców/dzieci na pokładzie, zapewne były tak oznaczane rodziny.¶

In [23]:
matryca_kor = df[df['survived'] == 1].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(matryca_kor, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla przeżywalności")
plt.show()
No description has been provided for this image
In [22]:
matryca_kor = df[df['survived'] == 0].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(matryca_kor, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji ze śmierlelnością")
plt.show()
No description has been provided for this image

Dla oznaczonych jako ofiary liczba dzieci korelauje z liczbą współmałżonków na pokładzie. Umierali razem?¶

In [59]:
df['body'].count()
Out[59]:
121

121 ciał wydobytych. Większości nie odnaleziono.¶

In [31]:
df["sex"].value_counts()
Out[31]:
1.0    843
0.0    466
Name: sex, dtype: int64
In [30]:
df[(df['parch'] == 0) & (df["sibsp"] == 0) & (df['sex'] == 0)].count()
Out[30]:
pclass       194
survived     194
name         194
sex          194
age          151
sibsp        194
parch        194
ticket       194
fare         194
cabin         46
embarked     192
boat         130
body           3
home.dest     93
dtype: int64
In [33]:
df[(df['sibsp'] == 0) & (df['sex'] == 0) & (df["parch"] == 0) & (df['survived'] == 0)].count()
Out[33]:
pclass       52
survived     52
name         52
sex          52
age          38
sibsp        52
parch        52
ticket       52
fare         52
cabin         3
embarked     52
boat          0
body          3
home.dest    16
dtype: int64

194 - tyle kobiet mogło płynąć statkiem samotnie, z czego 52 nie przeżyło.¶

In [34]:
df[(df['sibsp'] == 0) & (df['sex'] == 1) & (df["parch"] == 0)].count()
Out[34]:
pclass       596
survived     596
name         596
sex          596
age          439
sibsp        596
parch        596
ticket       596
fare         595
cabin         85
embarked     596
boat          99
body          80
home.dest    287
dtype: int64
In [35]:
df[(df['sibsp'] == 0) & (df['sex'] == 1) & (df["parch"] == 0) & (df['survived'] == 0)].count()
Out[35]:
pclass       499
survived     499
name         499
sex          499
age          364
sibsp        499
parch        499
ticket       499
fare         498
cabin         56
embarked     499
boat           4
body          80
home.dest    230
dtype: int64

Zdecydowana większość mężczyzn płynących samotnie nie przeżyła.¶

In [62]:
df[df["age"] < 18].count()
Out[62]:
pclass       154
survived     154
name         154
sex          154
age          154
sibsp        154
parch        154
ticket       154
fare         154
cabin         23
embarked     154
boat          77
body           5
home.dest     89
dtype: int64
In [59]:
df[(df['age'] < 18) & (df['survived'] == 0)].count()
Out[59]:
pclass       73
survived     73
name         73
sex          73
age          73
sibsp        73
parch        73
ticket       73
fare         73
cabin         2
embarked     73
boat          0
body          5
home.dest    30
dtype: int64

Było 154 niepełnoletnich osób, 73 nie przeżyło, w tym odnaleziono 5 ciał.¶

In [36]:
nieletni = df[(df["age"] < 18) & (df['survived'] == 0)]
plt.figure(figsize=(8, 6))
sns.countplot(data=nieletni, x='sex')
plt.title('Ofiary nieletnie pod względem płci')
plt.xlabel('sex')
plt.ylabel('Count')
plot_filename = "sex_survival_18.png"
plt.savefig(plot_filename)
No description has been provided for this image

Większość to chłopcy.¶

In [37]:
nieletni = df[(df["age"] < 18)]
plt.figure(figsize=(8, 6))
sns.countplot(data=nieletni, x='parch')
plt.title('Nieletni pasażerowie a liczba osób z rodziny na statku')
plt.xlabel('parch')
plt.ylabel('Count')
plot_filename = "sex_survivallll.png"
plt.savefig(plot_filename)
No description has been provided for this image

Najwięcej nieletnich płynęło z 1 rodzicem.¶

In [38]:
nieletni = df[(df["age"] < 18) & (df['survived'] == 0)]
plt.figure(figsize=(8, 6))
sns.countplot(data=nieletni, x='parch')
plt.title('Ofiary nieletnie a liczba osób z rodziny na statku')
plt.xlabel('parch')
plt.ylabel('Count')
plot_filename = "sex_survival_child.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [4]:
nieletni = df[(df["age"] < 18) & (df['survived'] == 0)]
plt.figure(figsize=(8, 6))
sns.countplot(data=nieletni, x='sibsp')
plt.title('Ofiary nieletnie a liczba osób z rodziny na statku')
plt.xlabel('sibsp')
plt.ylabel('Count')
plot_filename = "parch_not_survival_correlation.png"
plt.savefig(plot_filename)
No description has been provided for this image

Ci, którzy nie przeżyli, w większości byli jedynakami.¶

In [5]:
nieletni = df[(df["age"] < 18) & (df['survived'] == 0)]
plt.figure(figsize=(8, 6))
sns.countplot(data=nieletni, x='parch')
plt.title('Ofiary nieletnie a liczba osób z rodziny na statku')
plt.xlabel('parch')
plt.ylabel('Count')
plot_filename = "ofiary_nieletnie_rodzina.png"
plt.savefig(plot_filename)
No description has been provided for this image

Większość nieletnich płynęła z 1 rodzicem, ale było też sporo samotnych płynących.¶

Ponad 20 dzieci płynęło samotnie.¶

In [40]:
kobiety_uratowaneK = df[(df["sex"] == 0) & (df['survived'] == 1)]
plt.figure(figsize=(8, 6))
sns.countplot(data=kobiety_uratowaneK, x="pclass")
plt.title('Uratowane kobiety a klasa')
plt.xlabel('pclass')
plt.ylabel('Count')
plot_filename = "class_kobiety.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [41]:
kobiety_uratowane_port = df[(df["sex"] == 1) & (df['survived'] == 1)]
plt.figure(figsize=(8, 6))
sns.countplot(data=kobiety_uratowane_port, x="pclass")
plt.title('Uratowani mężczyźni a klasa')
plt.xlabel('pclass')
plt.ylabel('Count')
plot_filename = "class_survival_male.png"
plt.savefig(plot_filename)
No description has been provided for this image

Większość uratowanych kobiet płynęła w klasie 1, a mężczyźni w klasie 3.¶

Uratowane kobiety płynęły w większości klasą 1, a mężczyźni klasą 3.¶

In [42]:
df.groupby("sex", as_index=False)["pclass"].value_counts()
Out[42]:
sex pclass count
0 0.0 3.0 216
1 0.0 1.0 144
2 0.0 2.0 106
3 1.0 3.0 493
4 1.0 1.0 179
5 1.0 2.0 171
In [21]:
kobiety_martwe = df[(df["sex"] == 0) & (df['survived'] == 0)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(kobiety_martwe, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji nieprzeżywalności kobiet")
plt.show()
No description has been provided for this image

Korelacja z ceną biletu i współprasażerami. Umierały z rodziną? Korelacja znalezionego ciała z klasą.¶

In [20]:
kobiety_uratowane = df[(df["sex"] == 0) & (df['survived'] == 1)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(kobiety_uratowane, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla kobiet uratowanych")
plt.show()
No description has been provided for this image

Cena biletu koreluje z wiekiem.¶

In [19]:
mezczyzni_martwi = df[(df["sex"] == 1) & (df['survived'] == 0)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(mezczyzni_martwi, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla mężczyzn-ofiar")
plt.show()
No description has been provided for this image

U mężczyzn korelacja ze współprasażerami jest mniejszą, większość płynęła sama. Korelacja liczby rodzeństwa/małżonków z ceną. Być może przekłada się to na klasę, którą płynęli.¶

In [18]:
mezczyzni_uratowani = df[(df["sex"] == 1) & (df['survived'] == 1)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(mezczyzni_uratowani, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla mężczyzn, którzy przeżyli")
plt.show()
No description has been provided for this image

Widać mniejszą korelację ceny biletu z liczbą rodzeństwa/małżonków. Być może przekłada się to na klasę, którą płynęli.¶

In [49]:
sns.pairplot(df, hue='survived', palette="pastel")
Out[49]:
<seaborn.axisgrid.PairGrid at 0x216aac48f50>
No description has been provided for this image

Przeżyło więcej pasażerów, którzy mieli droższy bilet, płynęli samotnie i płynęli w klasie 1.¶

In [15]:
sns.pairplot(df, hue='sex', palette="pastel")
Out[15]:
<seaborn.axisgrid.PairGrid at 0x216a00406d0>
No description has been provided for this image

Znaczna przewaga ofiar wśród mężczyzn. Nie było kobiet powyżej 40 lat. W klasie 1 i 2 porównywalna liczba kobiet i mężczyzn, w klasie 3 znacznie więcej mężczyzn. Kobiety znacznie częściej płynęły z osobą towarzyszącą.¶

In [48]:
mezczyzni_uratowani_class = df[(df["sex"] == 1) & (df['survived'] == 1)]
sns.pairplot(mezczyzni_uratowani_class, hue='pclass', palette="pastel")
Out[48]:
<seaborn.axisgrid.PairGrid at 0x216a640d890>
No description has been provided for this image

Uratowani mężczyźni często płynęli w klasie 1 i mieli do 40 lat.¶

Tańsze bilety wiązały się z klasą 3. Najmłodsi mężczyźni płynęli w klasie 2, a najstarszi w klasie 3.¶

In [50]:
mezczyzni_umarli_class = df[(df["sex"] == 1) & (df['survived'] == 0)]
sns.pairplot(mezczyzni_umarli_class, hue='pclass', palette="pastel")
Out[50]:
<seaborn.axisgrid.PairGrid at 0x216a7ad9350>
No description has been provided for this image

Tutaj większa przewaga klasy 3. Większość mężczyzn, którzy nie przeżyli, płynęła samotnie w klasie 3.¶

In [51]:
mezczyzni_class1 = df[(df["sex"] == 1) & (df['pclass'] == 1)]
sns.pairplot(mezczyzni_class1, hue='survived', palette="pastel")
Out[51]:
<seaborn.axisgrid.PairGrid at 0x216b029b910>
No description has been provided for this image

Mężczyźni płynący w klasie 1 przeżyli, jeśli mieli tańszy bilet (płynęli na krótszym dystansie?) i byli młodsi (do 40 lat) i płynęli samotnie.¶

In [52]:
kobiety_class1 = df[(df["sex"] == 0) & (df['pclass'] == 1)]
sns.pairplot(kobiety_class1, hue='survived', palette="pastel")
Out[52]:
<seaborn.axisgrid.PairGrid at 0x216b7831bd0>
No description has been provided for this image

W większości kobiety płynące w klasie 1 przeżyły.¶

Ofiary zdarzały się wśród kobiet, które płynęły samotnie.¶

Nie przeżyło niemowle płci żeńskiej, płynące 1 klasą.¶

In [53]:
kobiety_class3 = df[(df["sex"] == 0) & (df['pclass'] == 3)]
sns.pairplot(kobiety_class3, hue='survived', palette="pastel")
Out[53]:
<seaborn.axisgrid.PairGrid at 0x216b86ead90>
No description has been provided for this image

W klasie 3 było więcej przypadków ofiar wśród kobiet.¶

Kobiety, które płynęły na droższym bilecie (dłuższym rejsem?) w tej klasie, nie przeżyły.¶

osoby, które płynęły w towarzystwie od 3 do 8 osób, przeżyły.¶

Ofiary wśród kobiet z podziałem na klasy.¶

In [54]:
kobiety_ofiary_class = df[(df["sex"] == 0) & (df['survived'] == 0)]
sns.pairplot(kobiety_ofiary_class, hue='pclass', palette="pastel")
Out[54]:
<seaborn.axisgrid.PairGrid at 0x216bb5644d0>
No description has been provided for this image

Wszędzie przewaga klasy 3.¶

Poniżej pairplot dla kobiet płynących całkowicie samotnie.¶

In [55]:
kobiety_parch0 = df[(df["sex"] == 0) & (df['parch'] == 0) & (df['sibsp'] == 0)]
sns.pairplot(kobiety_parch0, hue='survived', palette="pastel")
Out[55]:
<seaborn.axisgrid.PairGrid at 0x216c2b2c790>
No description has been provided for this image

Większość przeżyła. Nie udało się przeżyć samotnym kobietom, jeśli płynęły szczególnie w klasie 3 oraz gdy miały poniżej 30 lat.¶

In [61]:
kobiety_uratowane_class = df[(df["sex"] == 0) & (df['survived'] == 1)]
sns.pairplot(kobiety_uratowane_class, hue='pclass', palette="pastel")
Out[61]:
<seaborn.axisgrid.PairGrid at 0x216dc071f90>
No description has been provided for this image

w klasie 1 płynęły kobiety starsze i na dalszy rejs (?).¶

In [56]:
kobiety_ofiary_class = df[(df["sex"] == 0) & (df['survived'] == 0)]
sns.pairplot(kobiety_ofiary_class, hue='pclass', palette="pastel")
Out[56]:
<seaborn.axisgrid.PairGrid at 0x216bea544d0>
No description has been provided for this image

Przewaga klasy 3 i mniej osób towarzyszących.¶

In [57]:
mezczyzni_ofiary_class = df[(df["sex"] == 1) & (df['survived'] == 1)]
sns.pairplot(mezczyzni_ofiary_class, hue='pclass', palette="pastel")
Out[57]:
<seaborn.axisgrid.PairGrid at 0x216c29c1090>
No description has been provided for this image
Spora część osób w klasie 1 i jednocześnie na dłuższym dystansie(?).¶

Poniżej mężczyżni płynący całkowicie samotnie.¶

In [60]:
mezczyzni_parch0 = df[(df["sex"] == 1) & (df['parch'] == 0) & (df['sibsp'] == 0)]
sns.pairplot(mezczyzni_parch0, hue='survived', palette="pastel")
Out[60]:
<seaborn.axisgrid.PairGrid at 0x216d2c82d90>
No description has been provided for this image

Większość nie przeżyła. Udało się przeżyć tym do 20 r.ż.¶

In [62]:
mezczyzni_class3 = df[(df["sex"] == 1) & (df['pclass'] == 3)]
sns.pairplot(mezczyzni_class3, hue='survived', palette="pastel")
Out[62]:
<seaborn.axisgrid.PairGrid at 0x216e0834250>
No description has been provided for this image

Mężczyznom z klasy 3 najczęściej udało się przeżyć, jeśli płynęli samotnie lub z 1 osobą i mieli do 18 lat.¶

In [63]:
uratowani_port = df[(df['survived'] == 1)]
sns.pairplot(uratowani_port, hue='embarked', palette="pastel")
Out[63]:
<seaborn.axisgrid.PairGrid at 0x216e0a3c4d0>
No description has been provided for this image

Pasażerowie klasy 2 i 3 wchodzili na statek najczęściej portem S. W klasie 1 wchodzili równie często S, jak i Q.¶

In [17]:
klasa1 = df[(df["pclass"] == 1)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(klasa1, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla klasy 1")
plt.show()
No description has been provided for this image
In [14]:
klasa2 = df[(df["pclass"] == 2)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(klasa2, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla klasy 2")
plt.show()
No description has been provided for this image
In [12]:
klasa3 = df[(df["pclass"] == 3)].corr(numeric_only=True)
plt.figure(figsize=(8, 6))
sns.heatmap(klasa3, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title("Matryca korelacji dla klasy 3")
plt.show()
No description has been provided for this image

W matrycy dla klasy 3 widać największą korelację ceny biletu (dystansem?) z towarzyszami podróży/rodziną/dziećmi. Tylko w klasie 1 i 2 ukazała się korelacja przeżywalności ze współtowarzyszami na statku i z płcią (być może dlatego, że tymi klasami płynęło więcej kobiet i młodszych osób).¶

In [30]:
klasa1 = df[(df["pclass"] == 1)]
plt.figure(figsize=(8, 6))
sns.countplot(data=klasa1, x="parch")
plt.title('Klasa 1 a rodzina')
plt.xlabel('parch')
plt.ylabel('Count')
plot_filename = "klasa1_parch.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [31]:
klasa1_sibsp = df[(df["pclass"] == 1)]
plt.figure(figsize=(8, 6))
sns.countplot(data=klasa1_sibsp, x="sibsp")
plt.title('Klasa 1 a rodzina 2.0')
plt.xlabel('sibsp')
plt.ylabel('Count')
plot_filename = "klasa1_sibsp.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [29]:
klasa2 = df[(df["pclass"] == 2)]
plt.figure(figsize=(8, 6))
sns.countplot(data=klasa2, x="parch")
plt.title('Klasa 2 a rodzina')
plt.xlabel('parch')
plt.ylabel('Count')
plot_filename = "klasa2_parch.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [33]:
klasa2_sibsp = df[(df["pclass"] == 2)]
plt.figure(figsize=(8, 6))
sns.countplot(data=klasa2_sibsp, x="sibsp")
plt.title('Klasa 2 a rodzina 2.0')
plt.xlabel('sibsp')
plt.ylabel('Count')
plot_filename = "klasa2_sibsp.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [28]:
klasa3 = df[(df["pclass"] == 3)]
plt.figure(figsize=(8, 6))
sns.countplot(data=klasa1, x="parch")
plt.title('Klasa 3 a rodzina')
plt.xlabel('parch')
plt.ylabel('Count')
plot_filename = "klasa3_parch.png"
plt.savefig(plot_filename)
No description has been provided for this image
In [34]:
klasa3_sibsp = df[(df["pclass"] == 3)]
plt.figure(figsize=(8, 6))
sns.countplot(data=klasa3_sibsp, x="sibsp")
plt.title('Klasa 3 a rodzina 2.0')
plt.xlabel('sibsp')
plt.ylabel('Count')
plot_filename = "klasa3_sibsp.png"
plt.savefig(plot_filename)
No description has been provided for this image

W klasie 3 płynęło więcej wielodzietnych rodzin?¶

In [38]:
sns.pairplot(df, hue='embarked', palette="pastel")
Out[38]:
<seaborn.axisgrid.PairGrid at 0x2a2eade1e90>
No description has been provided for this image

Większość ofiar z portu S, młodsi płynęli z portu C i Q.¶

Port S i C pokrywają się, nie widać danych dla portu Q.¶

Wnioski¶

Na przeżycie miały większe szanse kobiety, osoby płynące w klasie 1 oraz z osobą/osobami towarzyszącymi. Przeżywalność koreluje z rodziną na pokładzie, więc można wnioskować, że ludzie byli ratowani wzraz z rodziną. Kobiety miały większe szanse na przeżycie, nawet jeśli płynęły samotnie. Mężczyźni mieli większe szanse na przeżycie, jeśli byli starsi. Przeciętna ofiara to mężczyzna w wieku 21 lat, który płynął w klasie 3. Nie udało się przeżyć samotnym kobietom, jeśli płynęły szczególnie w klasie 3 oraz gdy miały poniżej 30 lat. Dwójka niemowkaków z 12 zginęła. Najstarszemu pasażerowi udało się przeżyć. Większość pasażerów weszła na statek portem Southampton. W klasie 3 najprawdopodobniej płynęły rodziny wielodzietne, bo w tej klasie występuje największa liczba rodzeństwa na pokładzie. W klasie 2 i 3 max. 4 osoby towarzyszące.¶

In [ ]:
 
In [2]:
!jupyter nbconvert --to html "EDA_titanic_PJ.ipynb"
[NbConvertApp] Converting notebook EDA_titanic_PJ.ipynb to html
[NbConvertApp] WARNING | Alternative text is missing on 39 image(s).
[NbConvertApp] Writing 6769400 bytes to EDA_titanic_PJ.html
In [ ]:
 
In [ ]: